<?php
namespace Admin\Controller;
use Think\Controller;
use Think\Auth;
class CommonController extends Controller 
{
    /**
    *自动执行    
    */
    public function _initialize()
    {

        //auth权限  验证
        $path = MODULE_NAME .'/'.CONTROLLER_NAME.'/'.ACTION_NAME;
        //var_dump($path);
        $auth=new Auth();
        if($_SESSION['username']!='admin'){ 
           if(!$auth->check($path,$_SESSION['id'])) {
               $this->success('请联系管理员开通权限...',U('Admin/Login/out'));
               exit;
            };
        }

    }


    //公共方法 无限分类找子孙树
	public function gettree($arr,$id=0,$lev=0){
	   $tree = array();
	   foreach ($arr as $v) {
	   	if ($v['fid']==$id) {
	   		$v['lev'] = $lev;
	   		$tree[] = $v;

	   		$tree = array_merge($tree,$this->gettree($arr,$v['id'],$lev+1));
	   	}
	   }
	   return $tree;
	}

    //公共方法 cate栏目分组
    public function catetree($arr,$id=0)
    {
       $tree = array();
       foreach ($arr as $v) {
            if ($v['fid']==$id) {
                $v['son'] = $this->catetree($arr,$v['id']);
                $tree[] = $v;

            }
       }
       return $tree;
    }










}